<!-- 我的审核 -->
import func from './vue-temp/vue-editor-bridge';
<template lang="html">
<div>
  <Tabs v-if='isProcessList' :value="tab_name" @on-click="changeTabs" ref="tabs">
    <TabPane label="正在审核" name="审核中" key="key1">
      <Card :bordered="false">
        <p slot="title">正在审核</p>
        <p>
          <Table border :columns="zzsh_columns" :data="list_datas" :loading="list_load"></Table>
        </p>
        <Row style="padding:10px 0">
          <Col span="24">
          <Page style="float:right" :total="page_total" :current="page_current" :page-size="page_size" show-total
            @on-change="changePage" @on-page-size-change="changePageSize" />
          </Col>
        </Row>
      </Card>
    </TabPane>
    <TabPane label="已审核" name="已审核" key="key2">
      <card>
        <p slot="title">已审核</p>
        <Row>
          <Col span="2">
          <h3>审核日期</h3>
          </Col>
          <Col span="3">
          <DatePicker type="date" v-model="lookup.StartTime" @on-change="startTime" format="yyyy-MM-dd" placeholder="开始时间"></DatePicker >
          </Col>
          <Col span="3">
          <DatePicker type="date" v-model="lookup.EndTime" @on-change="endTime" format="yyyy-MM-dd" placement="bottom-end" placeholder="结束时间"></DatePicker >
          </Col>
          <Col style="border:1px #e8eaec solid;text-align: center;padding:5px 0" span="4">总计</Col>
          <Col style="border:1px #e8eaec solid;text-align: center;padding:5px 0" span="4">{{allScore.bsum?allScore.bsum:'0个报告书0个报告表'}}</Col>
          <Col style="border:1px #e8eaec solid;text-align: center;padding:5px 0" span="4">绩效{{allScore.bscore}}</Col>
            <Button @click="lookupBtn" type="info">查看</Button>
        </Row>
        <Table border :columns="ysh_columns" :data="list_datas" :loading="list_load" style="margin-top: 10px" ref="print"></Table>
        <Row>
            <Col style="border:1px #e8eaec solid;text-align: center;padding:5px 0" span="3">合计</Col>
            <Col style="border:1px #e8eaec solid;text-align: center;padding:5px 0" span="15">{{totalReport?totalReport:'0个报告书0个报告表'}}</Col>
            <Col style="border:1px #e8eaec solid;text-align: center;padding:5px 0" span="3">绩效{{totalScore}}</Col>
            <Col style="border:1px #e8eaec solid;text-align: center;padding:5px 0" span="3">
              <Button type="primary" @click="scorePrint()" size="small">打印</Button>
            </Col>
        </Row>
        <Row style="padding:10px 0">
          <Col span="24">
          <Page style="float:right" :total="page_total" :current="page_current" :page-size="page_size" show-total @on-change="changePage" @on-page-size-change="changePageSize" />
          </Col>
        </Row>
      </card>
    </TabPane>
  </Tabs>
  <card :bordered="false" v-else>
      <p slot="title">
        <Row style="padding-bottom: 10px" :gutter="32">
          <Col span="2">
          <h4>项目流程单</h4>
          </Col>
          <Col span="2" style="color:#999" @click.native="isProcessList = true"> 返回>>
          </Col>
        </Row>
      </p>
      <table width="100%" cellpadding="0" cellspacing="0" border="1">
        <tr>
          <th colspan="4">项目流程单</th>
        </tr>
        <tr>
          <th>流程</th>
          <th>操作</th>
          <th>操作记录</th>
          <th>功能</th>
        </tr>
        <tbody v-for="(item,index) in processList" :key=index>
          <tr>
            <td rowspan="2" width="25%">{{item.name}}</td>
            <td width="25%">保存</td>
            <td width="25%">
              <p v-if="item.saveTime.length>0" v-for="(e,i) in item.saveTime" :key=i>{{e}}</p>
            </td>
            <td rowspan="2">
              <PrintButton style="display:inline-block" Url="print/printProject" :Project_id="routerId" :stats='item.submitTime.length>0||item.saveTime.length>0?false:true'></PrintButton>
              <ButtonShow style="display:inline-block" :viewOnly=1 :rName="jumpRouterName[index]" :Project_id="routerId" :stats='item.submitTime.length>0||item.saveTime.length>0?false:true'></ButtonShow>
            </td>
          </tr>
          <tr>
            <td>提交</td>
            <td>
              <p v-if="item.submitTime.length>0" v-for="(e,i) in item.submitTime" :key=i>{{e}}</p>
            </td>
          </tr>
        </tbody>
      </table>
  </card>
  <!-- <Modal
        v-model="isModal"
        title="项目查看"
        @on-ok="ok"
        @on-cancel="cancel">
        <Row type="flex" justify="center" align="middle" class="code-row-bg" style="height: 300px; overflow: scroll;" >
        <Col span="12">正文</Col>
        <Col span="12"><DownloadButton :downData="this.infoDoc.Text_report" type="info"></DownloadButton></Col><Divider />
        <Col span="12">委托书</Col>
        <Col span="12"><DownloadButton :downData="this.infoDoc.Project_trust_instrument" type="info"></DownloadButton></Col><Divider />
        <Col span="12">备案/立项文件</Col>
        <Col span="12"><DownloadButton :downData="this.infoDoc.Create_project_doc" type="info"></DownloadButton></Col><Divider />
        <Col span="12">土地文件</Col>
        <Col span="12"><DownloadButton :downData="this.infoDoc.Land_doc" type="info"></DownloadButton></Col><Divider />
        <Col span="12">规划文件</Col>
        <Col span="12"><DownloadButton :downData="this.infoDoc.Planning_doc" type="info"></DownloadButton></Col><Divider />
        <Col span="12">执行标准函</Col>
        <Col span="12"><DownloadButton :downData="this.infoDoc.AStandard_letter" type="info"></DownloadButton></Col><Divider />
        <Col span="12">地理位置图</Col>
        <Col span="12"><DownloadButton :downData="this.infoDoc.Coordinate_map" type="info"></DownloadButton></Col><Divider />
        <Col span="12">周围环境概况图</Col>
        <Col span="12"><DownloadButton :downData="this.infoDoc.Project_env_overview" type="info"></DownloadButton></Col><Divider />
        <Col span="12">项目平面图</Col>
        <Col span="12"><DownloadButton :downData="this.infoDoc.Project_flat_map" type="info"></DownloadButton></Col><Divider />
        <Col span="12">项目监测布点图</Col>
        <Col span="12"><DownloadButton :downData="this.infoDoc.Actual_monitor_point_map" type="info"></DownloadButton></Col><Divider />
        <Col span="12">项目水系图</Col>
        <Col span="12"><DownloadButton :downData="this.infoDoc.River_system_map" type="info"></DownloadButton></Col><Divider />
        <Col span="12">基础信息表</Col>
        <Col span="12"><DownloadButton :downData="this.infoDoc.Basic_information" type="info"></DownloadButton></Col>
        </Row>
    </Modal> -->
</div>
  
</template>

<script>
  import libs from "../../libs/uploads";
  export default {
    data() {
      return {
        // 操作提示
        Offbol: false,
        // 总计报告书报告表
        totalReport: '', 
        // 绩效
        totalScore: '',
        jumpRouterName:['createProgram','dataCollection','reconnaissanceTrip','environmentQuality','reportReview','reportTria','technologyAssessment','reportApproval','reportPublicity','reportArchives'],
        routerId: '',
        processList: [],  //流程单
        isProcessList: true, //是否显示流程单
        tab_name: '审核中',
        zzsh_columns: [{
            align: 'center',
            title: '项目编号',
            key: 'ProjectNumber'
          },
          {
            align: 'center',
            title: '项目名称',
            key: 'ProjectName'
          },
          {
            align: 'center',
            title: '公司级别',
            key: 'Project_level_name'
          },
          {
            align: 'center',
            title: '状态',
            key: 'AuditType'
          },
          {
            align: 'center',
            title: '操作',
            render: (h, params) => {
              return h("div", [
                h("Button", {
                    props: {
                      type: "primary",
                      size: "small"
                    },
                    style: {
                      marginRight: "5px",
                      color: "#ffffff",
                      background: "#2996ff",
                      border: "none",
                      padding: "0px 5px"
                    },
                    on: {
                      click: () => {
                        this.toShow(params.row.ProjectId)
                      }
                    }
                  },
                  '查看'
                ),
                h("Button", {
                    props: {
                      type: "primary",
                      size: "small",
                      disabled: this.getButton(params.index,params.row.AuditType)
                      // (params.index,params.row.Stats)
                    },
                    style: {
                      marginRight: "5px",
                      // color: "#ffffff",
                      // background: "#19be6b",
                      border: "none",
                      padding: "0px 5px"
                    },
                    on: {
                      click: () => {
                        // 审核
                        // console.log(params.row)
                        this.audit(params.row.Id, params.row.AuditType, params.row.Pid)
                      }
                    }
                  },
                  '审核'
                )
              ])
            }
          },
        ],

        ysh_columns: [{
            title: '序号',
            type: 'index',
            align: 'center'
          },
          {
            title: '项目编号',
            key: 'ProjectNumber',
            align: 'center'
          },
          {
            title: '项目名称',
            key: 'ProjectName',
            align: 'center'
          },
          {
            title: '公司级别',
            key: 'Project_level_name',
            align: 'center',
          },
          {
            title: '报告类型',
            key: 'ReportType',
            align: 'center'
          },
          {
            title: '审批部门',
            key: 'ApprovalUnit',
            align: 'center'
          },
          {
            title: '状态',
            key: 'AuditType',
            align: 'center',
          },
          {
            title: '审核日期',
            key: 'AuditDate',
            align: 'center'
          },
          {
            title: '审核绩效',
            align: 'center',
            render: (h,params) =>{
              var self = params.row.AuditScore
              return h("Input",{
                  props: {
                    value: params.row.AuditScore
                  },
                  on : {
                    'on-blur': ()=> {
                      this.score(params.row.Id,self)
                    },
                    input: (event)=>{
                      self = event
                      console.log(self)
                      this.Offbol = true;
                      console.log(this.Offbol)
                    }
                  }
                })
            }
          },
          {
            title: '操作',
            align: 'center',
            render: (h, params) => {
              return h("div", [
                h("Button", {
                    props: {
                      type: "primary",
                      size: "small"
                    },
                    on: {
                      click: () => {
                        this.toShow(params.row.ProjectId)
                      }
                    }
                  },
                  '查看'
                )
              ])
            }
          }
        ],

        list_datas: [],
        list_load: true,
        page_total: 0,
        page_current: 1,
        page_size: 10,
        lookup: {},
        page2: '',
        allScore: {},
        isPage: '',
        isModal: false,
        modalData: {},
        infoDoc: {},
        buttonDis: '',
        dataTypeInfo: [],
      }
    },
    mounted() {
      console.log(this.isProcessList)
      // 通过审核跳转到已审核
      if(this.$route.params.success==1) {
        this.tab_name = '已审核'
      }
      // 判断是否存返回而来
      let info = this.$store.state.myProjectCheck
      console.log(info)
      if (info.tab_name) {
        this.tab_name = info.tab_name
        this.page_size = info.page_size
        // console.log(info.page_current);
        this.getList(info.page_current)
        this.page2 = info.page_current
      } else {
        this.getList(1)
      }
      //绩效
      this.getAllScore()
    },
    methods: {
      getButton(i,stats){
        // console.log(stats)
          if(this.dataTypeInfo[i] == stats){
            return false
          }else{
            return true
          }
      },
      showModals() {
          this.$refs.tabs.activeKey = '审核中'
          this.modal = {
              title: name,
              visible: true
          }
      },
      ok () {},
      cancel () {},
      scorePrint(){
        console.log(this.lookup.EndTime)
        let baseUrl = libs.uploads2();
        if(this.lookup.EndTime && this.lookup.EndTime) {
          window.open(baseUrl + 'print/printAuditBill?' + 'StartTime=' + this.lookup.StartTime + '&EndTime=' + this.lookup.EndTime +'&PageIndex=' + this.page_current , 'newwindow')
        }else{
          window.open(baseUrl + 'print/printAuditBill?' + 'PageIndex=' + this.page_current , 'newwindow')
        }
        
      },
      getAllScore(){
        axios.get('audit/countAudit')
        .then((res)=>{
          this.allScore = res
        }).catch((err)=>{
          console.log(err)
        })
      },
      score(Id,AuditScore){                //绩效
        axios.post('audit/saveOrUpdate',{
          Id: Id,
          AuditScore: AuditScore
        }).then((res)=>{
          console.log(res)

          if(this.Offbol){
            this.Offbol = false;
            this.$Message.success(res._MESSAGE)
          }
          this.getAllScore()
          this.getList(1)
        }).catch((err)=>{
          console.log(err)
        })
      },
      lookupBtn(){            //查找
        console.log(this.lookup)
        axios.get('/audit/findByAuditor', {
          params: {
            Stats: this.tab_name,
            PageIndex: this.page2 + 1,
            PageSize: this.page_size,
            StartTime: this.lookup.StartTime,
            EndTime: this.lookup.EndTime
          }
        }).then((res) => {
          console.log(res)
          this.list_datas = res.data
          this.totalReport = res.sum
          this.totalScore = res.score
          let list_datas = this.list_datas
          list_datas.forEach(e => {
             if(e.Name != null){
              e['Project_level_name'] = e.Name
            } else {
              e['Project_level_name'] = '一级账号'
            }
          });
          
          this.list_load = false
        }).catch(err => {
          console.log(err)
          this.$Message.error('请求失败!')
        })
      },
      startTime(e){
        this.lookup.StartTime = e;
      },
      endTime(e){
        this.lookup.EndTime = e;
      },
      // 项目流程单
      getProcessList(ProjectId) {
        axios.post('/audit/findSubmitTime',{ProjectId:ProjectId}).then(res=>{
          console.log(res)
          if(res._STATUS == 1) {
          this.processList = res.data
          }
        }).catch(err=>{
          console.log(err)
        }) 
      },
      getList(page) {
        this.list_load = true
        axios.get('/audit/findByAuditor', {
          params: {
            Stats: this.tab_name,
            PageIndex: page,
            PageSize: this.page_size
          }
        }).then((res) => {
          // console.log(res)
          this.totalReport = res.sum
          this.totalScore = res.score
          this.page_current = page
          this.page_total = res.count
          this.list_datas = res.data
          let list_datas = this.list_datas
          // console.log(this.list_datas)
          list_datas.forEach(e => {
            
             if(e.Name != null){
              e['Project_level_name'] = e.Name
            } else {
              e['Project_level_name'] = '一级账号'
            }
            switch (e.Stats+'') {
              case "1":
              this.dataTypeInfo.push(e.AuditType)
                e['AuditType'] = "创建项目"
                break;
              case "2":
              this.dataTypeInfo.push(e.AuditType)
                e['AuditType'] = "资料收集"
                break;
              case "3":
              this.dataTypeInfo.push(e.AuditType)
                e['AuditType'] = "现场踏勘"
                break;
              case "4":
              this.dataTypeInfo.push(e.AuditType)
                e['AuditType'] = "环境质量"
                break;
              case "5":
              this.dataTypeInfo.push(e.AuditType)
                e['AuditType'] = "报告编制及审核"
                break;
              case "6":
              this.dataTypeInfo.push(e.AuditType)
                e['AuditType'] = "一审"
                break;
              case "7":
              this.dataTypeInfo.push(e.AuditType)
                e['AuditType'] = "二审"
                break;
              case "8":
              this.dataTypeInfo.push(e.AuditType)
                e['AuditType'] = "初审"
                break;
              case "9":
              this.dataTypeInfo.push(e.AuditType)
                e['AuditType'] = "复审"
                break;
              case "10":
              this.dataTypeInfo.push(e.AuditType)
                e['AuditType'] = "终审"
                break;
              case "11":
              this.dataTypeInfo.push(e.AuditType)
                e['AuditType'] = "报告送审"
                break;
              case "12":
              this.dataTypeInfo.push(e.AuditType)
                e['AuditType'] = "技术评估"
                break;
              case "13":
              this.dataTypeInfo.push(e.AuditType)
                e['AuditType'] = "报告报批"
                break;
              case "14":
              this.dataTypeInfo.push(e.AuditType)
                e['AuditType'] = "报告公示"
                break;
              case "15":
              this.dataTypeInfo.push(e.AuditType)
                e['AuditType'] = "报告存档"
                break;
              case "16":
              this.dataTypeInfo.push(e.AuditType)
                e['AuditType'] = "项目结束"
                break;
            }
          });
          console.log(this.dataTypeInfo)
          // this.getButton2(res.data)
          this.list_load = false
        }).catch(err => {
          console.log(err)
          this.$Message.error('请求失败!')
        })
      },
      changePage(page) {
        this.page_current = page
        this.getList(page)
        this.dataTypeInfo = []
      },
      changePageSize(size) {
        this.page_size = size
        this.getList(1)
        this.dataTypeInfo = []
      },
      changeTabs(tab_name) {
        this.tab_name = tab_name
        console.log(this.tab_name);
        this.list_load = true
        this.page_current = 1
        this.page_total = 0
        this.getList(1)
      },
      toShow(ProjectId) {
        // this.isModal = true
        // console.log(Project_id)
        // this.getModalData(Project_id)
        this.routerId = ProjectId
        this.isProcessList = false
        this.getProcessList(ProjectId)
        // 保存 当前详情
        this.$store.commit('setMyProjectCheck', {
          ProjectId,
          // tab_name: this.tab_name,
          page_size: this.page_size,
          page_current: this.page_current,
        })

        // this.$router.push({
        //   name: 'underway',
        //   query: {
        //     Project_id,
        //   }
        // })
      },
      //跳转对应审核
      audit(Id, Atype, ProjectId) {
        let route_name = ''
        switch (Atype) {
          case '一审':
            route_name = 'myFirstInstance'
            Atype = 0
            break;
          case '二审':
            route_name = 'mySecondInstance'
            Atype = 1
            break;
          case '初审':
            route_name = 'myfirstTrial'
            Atype = 2
            break;
          case '复审':
            route_name = 'myrEexamine'
            Atype = 3
            break;
          case '终审':
            route_name = 'mylast'
            Atype = 4
            break;
          default:
            console.log(Atype)
            return
        }

        axios.get('audit/isChange', {
          params: {
            Id: Id
          }
        }).then(res => {
          // console.log(res)
          if (res.stats == "0") {
            // 审核页
            this.$router.push({
              name: route_name,
              query: {
                ProjectId,
                Atype,
                Id,
              }
            })
          } else {
            // 审核修改页
            this.$router.push({
              name: route_name + 'Modification',
              query: {
                ProjectId,
                Atype,
                Id,
              }
            })
          }

        }).catch(err => {
          this.$Message.error('请求失败')
          console.log(err)
        })
      },
      getModalData(id){
        axios.get('/projectInformation/findProjectByID',{
          params:{
            id
          }
        }).then((res)=>{
          this.infoDoc = res.doc
          console.log(this.infoDoc)
        })
      }
    },
  }

</script>

<style lang="css">
</style>